<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <a href="${base}/platform/wx/msg/user/${wxid!}" data-pjax id="_reload"></a>

    <div class="btn-group" style="padding-top: 5px;">
        <div >
            <select id="wxid" name="wxid" class="form-control">
                <% for(o in wxList){
                %>
                <option value="${o.id}" <%if(o.id==wxid){%>selected<%}%>>${o.appname}</option>
                <%
                } %>
            </select>
        </div>
    </div>
    <div class="pull-right">
        <button class="btn btn-primary navbar-btn" onclick="sublime.toggleFilter('.cd-panel')"><i
                class="fa fa-sliders"></i> 筛选
        </button>
    </div>
</header>
<div class=panel-body style="padding-top: 50px;">
    <div class="table-responsive no-border">
        <table class="table table-bordered table-striped mg-t datatable">
            <thead>
            <tr>
                <th>Openid</th>
                <th>昵称</th>
                <th>消息内容</th>
                <th>接收时间</th>
                <th>回复状态</th>
                <th>操作</th>
        </table>
    </div>
    <div class="cd-panel from-right">
        <header class="cd-panel-header">
            <h4>高级筛选</h4>
        </header>
        <div class="cd-panel-container">
            <div class="cd-panel-content shadow">
                <div class="form-group">
                    <label for="nickname">昵称</label>
                    <input type="text" id="nickname" name="nickname" onclick="this.value=''" class="form-control" placeholder="昵称">
                </div>
                <div class="form-group">
                    <label for="content">内容</label>
                    <input type="text" id="content" name="content" onclick="this.value=''" class="form-control" placeholder="内容">
                </div>
                <button id="searchBtn" type="button" class="btn btn-default">查询</button>
            </div>
        </div>
    </div>
<div id="dialogDetail" class="modal fade bs-modal" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching": false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/wx/msg/user/data/${wxid!}",
                "type": "post",
                "data": function (d) {
                    d.nickname = $('#nickname').val();
                    d.content=$('#content').val();
                }
            },
            "order": [[3, "desc"]],
            "columns": [
                {"data": "openid", "bSortable": true},
                {"data": "nickname", "bSortable": true},
                {"data": "content", "bSortable": true},
                {"data": "opAt", "bSortable": true},
                {"data": "replyId", "bSortable": true}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        if (data) {
                            return moment(parseInt(data*1000)).format("YYYY-MM-DD HH:mm:ss");
                        }
                        return '';
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row) {
                        if (data) {
                            return '已回复';
                        }
                        return '未回复';
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row) {
                        var str='<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
                                ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">';
                        if (!row.replyId||row.replyId==0) {
                            str+='<li><a href="${base}/platform/wx/msg/user/reply/' + row.id + '?type=1"  data-toggle="modal" data-target="#dialogDetail">回复</a></li>';
                        }
                        str+= '<li><a href="${base}/platform/wx/msg/user/reply/' + row.id + '?type=0"  data-toggle="modal" data-target="#dialogDetail">查看</a></li>' +
                                '</ul></div>';
                        return str;
                    },
                    "targets": 5
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    $(function () {
        initDatatable();
        $("#wxid").on("change",function(){
            $("#_reload").attr("href","${base}/platform/wx/msg/user/"+$(this).val());
            $("#_reload").trigger("click");
        });
        $("#dialogDetail").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
        });
    });
</script>

<%}%>